package com.his.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.his.admin.service.OrderItemService;
import com.his.dao.domain.dto.ListDto;
import com.his.dao.domain.dto.MedicineListDto;
import com.his.dao.domain.entity.Medicine;
import com.his.dao.domain.entity.OrderItem;
import com.his.dao.domain.vo.ListVo;
import com.his.dao.mapper.MedicineMapper;
import com.his.dao.mapper.OrderItemMapper;
import com.his.util.result.RestResult;
import com.his.util.result.RestResultBuilder;
import com.his.util.util.MapUtil;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author fall
 * @since 2022-11-28
 */
@Service
@AllArgsConstructor
public class OrderItemServiceImpl extends ServiceImpl<OrderItemMapper, OrderItem> implements OrderItemService {
    private OrderItemMapper orderItemMapper;

    @Override
    public RestResult all(ListDto listDto) {
        OrderItem orderItem = MapUtil.conversionMapToObj((Map)listDto.getObj(),OrderItem.class);


        return new RestResultBuilder().success(ListVo
                .builder()
                .list(orderItemMapper.selectAll(
                        orderItem.getMedicineName(),
                        orderItem.getOrderId(),
                        listDto.getPage() * listDto.getPageSize(),
                        listDto.getPageSize()))
                .total(orderItemMapper.selectAllCount(
                        orderItem.getMedicineName(),
                        orderItem.getOrderId()
                ))
                .build());
    }
}
